
package guipk;

import commonpk.DBOperation;
import java.sql.SQLException;

/**
 *
 * @author EdwardLee
 */
public class PlayerInfoFrame extends javax.swing.JFrame {

    //*****************************************************
    /* 成员 */
    
    private int          playerId;            // 玩家账号         
    private DBOperation  DBO;                 // 数据库操作
    private String       playerName;          // 玩家名
    private int          playerGrade;         // 玩家等级
    private int          playerScore;         // 玩家积分
    //*****************************************************
    
    
    
    //*****************************************************
    /* 构造器 */
    public PlayerInfoFrame(int playerId) {
        initComponents();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.playerId = playerId;
        this.DBO = new DBOperation();
        
        //读取数据库
        // 生成查询语句
        String sql = "select * from PlayerTable where PlayerId=" + this.playerId;
        DBO.DBQuary(sql);
        try{
            DBO.getRs().first();
            this.playerName = DBO.getRs().getString("PlayerName");
            this.playerScore = DBO.getRs().getInt("PlayerScore");
            calcGrade();
            
        }catch(SQLException e){
            e.printStackTrace();
        }
        this.PlayerNameTextField.setText(this.playerName);
        this.PlayerGradeTextField.setText(String.valueOf(this.playerGrade));
        this.PlayerScoreTextField.setText(String.valueOf(this.playerScore));
    }
    //*****************************************************
    
    
    
    
    //******************************************************
    /* 其他方法 */
    
    // 计算等级
    public void calcGrade() {
        if(this.playerScore >= 0 && this.playerScore < 20){
            this.playerGrade = 1;
        }
        else if(this.playerScore < 40){
            this.playerGrade = 2;
        }
        else if(this.playerScore < 60){
            this.playerGrade = 3;
        }
        else if(this.playerScore < 80){
            this.playerGrade = 4;
        }
        else{
            this.playerGrade = 5;
        }
    }
    
    //******************************************************

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        PlayerNameLabel = new javax.swing.JLabel();
        PlayerGradeLabel = new javax.swing.JLabel();
        PlayerScoreLabel = new javax.swing.JLabel();
        PlayerNameTextField = new javax.swing.JTextField();
        PlayerGradeTextField = new javax.swing.JTextField();
        PlayerScoreTextField = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(102, 204, 255));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        PlayerNameLabel.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        PlayerNameLabel.setText("玩家名:");
        jPanel1.add(PlayerNameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 30, -1, -1));

        PlayerGradeLabel.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        PlayerGradeLabel.setText("玩家等级:");
        jPanel1.add(PlayerGradeLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 70, -1, -1));

        PlayerScoreLabel.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        PlayerScoreLabel.setText("玩家积分:");
        jPanel1.add(PlayerScoreLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 110, -1, -1));

        PlayerNameTextField.setBackground(new java.awt.Color(102, 204, 255));
        PlayerNameTextField.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanel1.add(PlayerNameTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 40, 100, -1));

        PlayerGradeTextField.setBackground(new java.awt.Color(102, 204, 255));
        PlayerGradeTextField.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanel1.add(PlayerGradeTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 70, 100, -1));

        PlayerScoreTextField.setBackground(new java.awt.Color(102, 204, 255));
        PlayerScoreTextField.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanel1.add(PlayerScoreTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 110, 70, -1));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PlayerInfoFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PlayerInfoFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PlayerInfoFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PlayerInfoFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                /*
                new PlayerInfoFrame().setVisible(true);
                */
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel PlayerGradeLabel;
    private javax.swing.JTextField PlayerGradeTextField;
    private javax.swing.JLabel PlayerNameLabel;
    private javax.swing.JTextField PlayerNameTextField;
    private javax.swing.JLabel PlayerScoreLabel;
    private javax.swing.JTextField PlayerScoreTextField;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
